package icu.lookyousmileface.notsafe;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * @author starrysky
 * @title: UnSafeSet
 * @projectName Juc_Pro
 * @description: Set不安全，set底层底层HashMap
 * @date 2021/1/291:00 下午
 */
public class UnSafeSet {
    public static void main(String[] args) {
        /**
         * 和List同理
         */
//        Set<String> set = new HashSet<>();
//        Set<String> set =  Collections.synchronizedSet(new HashSet<>());
        Set<String> set = new CopyOnWriteArraySet<>();
        for (int i = 0; i < 30; i++) {
            new Thread(() -> {
                set.add(UUID.randomUUID().toString().substring(0, 6));
                System.out.println(set);

            }, String.valueOf(i)).start();
        }
    }
}
